package site.marqstree.kotlin.library.base.ui.widget.banner

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.youth.banner.adapter.BannerAdapter
import kotlinx.android.synthetic.main.item_banner.view.*
import site.marqstree.kotlin.library.base.ui.R
import site.marqstree.kotlin.library.base.util.GlideUtil


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.base.ui.widget.banner
 * 文件名: ImageBannerAdapter
 * 创建者: marqstree
 * 创建时间: 2020/3/14 11:44
 * 描述: 通用图片Banner适配器
 */
//imageUrls:图片url数组
//mContext:Banner控件所在Activity/Fragment的上下文
class ImageBannerAdapter (imageUrls: List<String>, val mContext: Context)
    : BannerAdapter<String, RecyclerView.ViewHolder>(imageUrls){

    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): RecyclerView.ViewHolder {
        val itemView = LayoutInflater.from(parent!!.context)
            //依赖于ViewPager2，parent不能为null,最后一个参数也要写，否则报错
            .inflate(R.layout.item_banner, parent,false)
        return object : RecyclerView.ViewHolder(itemView){}
    }

    override fun onBindView(
        holder: RecyclerView.ViewHolder,
        url: String,
        position: Int,
        size: Int
    ) {
        GlideUtil.loadImage(mContext,
            url,
            holder.itemView.mBannerIv)
    }

}